package org.javaforever.gatescore.core;

import java.io.Serializable;

import org.javaforever.gatescore.complexverb.Assign;
import org.javaforever.gatescore.complexverb.ListMyActive;
import org.javaforever.gatescore.complexverb.ListMyAvailableActive;
import org.javaforever.gatescore.complexverb.Revoke;
import org.javaforever.gatescore.exception.ValidateException;
import org.javaforever.gatescore.utils.StringUtil;
import org.javaforever.gatescore.verb.Activate;
import org.javaforever.gatescore.verb.ActivateAll;
import org.javaforever.gatescore.verb.Add;
import org.javaforever.gatescore.verb.Clone;
import org.javaforever.gatescore.verb.CloneAll;
import org.javaforever.gatescore.verb.Delete;
import org.javaforever.gatescore.verb.DeleteAll;
import org.javaforever.gatescore.verb.Export;
import org.javaforever.gatescore.verb.ExportPDF;
import org.javaforever.gatescore.verb.ExportPPT;
import org.javaforever.gatescore.verb.ExportWord;
import org.javaforever.gatescore.verb.FilterExcel;
import org.javaforever.gatescore.verb.FilterPDF;
import org.javaforever.gatescore.verb.FilterPPT;
import org.javaforever.gatescore.verb.FilterWord;
import org.javaforever.gatescore.verb.FindById;
import org.javaforever.gatescore.verb.FindByName;
import org.javaforever.gatescore.verb.ListActive;
import org.javaforever.gatescore.verb.ListAll;
import org.javaforever.gatescore.verb.ListAllByPage;
import org.javaforever.gatescore.verb.SearchByFieldsByPage;
import org.javaforever.gatescore.verb.SearchByName;
import org.javaforever.gatescore.verb.SoftDelete;
import org.javaforever.gatescore.verb.SoftDeleteAll;
import org.javaforever.gatescore.verb.Toggle;
import org.javaforever.gatescore.verb.ToggleOne;
import org.javaforever.gatescore.verb.Update;
import org.javaforever.gatescore.vue.VueAPIJs;

public class FrontDummyPrism extends FrontPrism implements Comparable<FrontPrism>,Cloneable,Serializable {
	private static final long serialVersionUID = -6564911185715498575L;

	public void generateDummyPrismFromEnum() throws ValidateException, Exception {
		if (this.domain != null) {
			if (this.getPackageToken() != null) {
				this.domain.setPackageToken(packageToken);
			}

			FrontVerb listAll = new ListAll(this.domain);
			FrontVerb findbyid = new FindById(this.domain);
			FrontVerb findbyname = new FindByName(this.domain);
			FrontVerb searchbyname = new SearchByName(this.domain);
			FrontVerb listactive = new ListActive(this.domain);
			FrontVerb searchByFieldsByPage = new SearchByFieldsByPage(this.domain);
			FrontVerb export = new Export(this.domain);
			FrontVerb exportExcel = new Export(this.domain);
			FrontVerb exportPDF = new ExportPDF(this.domain);
			FrontVerb exportWord = new ExportWord(this.domain);
			FrontVerb exportPPT = new ExportPPT(this.domain);
			FrontVerb filterExcel = new FilterExcel(this.domain);
			FrontVerb filterPDF = new FilterPDF(this.domain);
			FrontVerb filterWord = new FilterWord(this.domain);
			FrontVerb filterPPT = new FilterPPT(this.domain);

			this.addVerb(listAll);
			this.addVerb(findbyid);
			this.addVerb(findbyname);
			this.addVerb(searchbyname);
			this.addVerb(listactive);
			this.addVerb(searchByFieldsByPage);
			this.addVerb(export);
			this.addVerb(exportExcel);
			this.addVerb(exportPDF);
			this.addVerb(exportWord);
			this.addVerb(exportPPT);
			this.addVerb(filterExcel);
			this.addVerb(filterPDF);
			this.addVerb(filterWord);
			this.addVerb(filterPPT);
			
			this.api = new VueAPIJs(this.domain);
			this.api.setTwinsverbs(this.twinsverbs);
			
			if (this.domain.manyToManies != null && this.domain.manyToManies.size() > 0) {
				for (FrontManyToMany mtm : this.domain.manyToManies) {
					String slaveName = mtm.getManyToManySalveName();
					String masterName = this.domain.getStandardName();
					if (listContainsDomain(this.projectDomains, masterName)
							&& listContainsDomain(this.projectDomains, slaveName)) {
						FrontDomain myslave = (FrontDomain)lookupDoaminInList(this.projectDomains, slaveName).clone();
						if (!StringUtil.isBlank(mtm.getSlaveAlias())){
							myslave.setAlias(mtm.getSlaveAlias());
							myslave.setAliasLabel(mtm.getSlaveAliasLabel());
						}
						FrontManyToMany mymtm = new FrontManyToMany(lookupDoaminInList(this.projectDomains, masterName),
								myslave,mtm.getMasterValue(),mtm.getValues());	
						mymtm.setSlaveAlias(myslave.getAlias());
						mymtm.setSlaveAliasLabel(mtm.getSlaveAliasLabel());
						mymtm.setStandardName("Link"+StringUtil.capFirst(masterName)+StringUtil.capFirst(myslave.getAliasOrName()));
						mymtm.setValues(mtm.getValues());
						this.manyToManies.add(mymtm);
						Assign assign = new Assign(mymtm);
						Revoke revoke = new Revoke(mymtm);
						ListMyActive lma = new ListMyActive(mymtm);
						ListMyAvailableActive lmaa = new ListMyAvailableActive(mymtm);
						addTwinsVerb(assign);
						addTwinsVerb(revoke);
						addTwinsVerb(lma);
						addTwinsVerb(lmaa);						
					} else {
						ValidateInfo validateInfo = new ValidateInfo();
						validateInfo.addCompileError("棱柱" + this.getText() + "多对多设置有误。");
						ValidateException em = new ValidateException(validateInfo);
						throw em;
					}
				}
			}
		}
	}

}
